from collections import deque
from typing import List, Optional


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


def make_tree(value: List[int]) -> Optional[TreeNode]:
    if not value:
        return None
    ans = TreeNode(value[0])
    n = len(value)
    index = 0
    floor = deque([ans])
    next_f = deque([])
    while index < n:
        while floor:
            root = floor.popleft()
            index += 1
            if index == n:
                break
            if value[index] or value[index] == 0:
                root.left = TreeNode(value[index])
                next_f.append(root.left)
            index += 1
            if index == n:
                break
            if value[index] or value[index] == 0:
                root.right = TreeNode(value[index])
                next_f.append(root.right)

        floor = next_f.copy()
        next_f.clear()
    print_tree(ans)
    return ans


def print_tree(root):
    # write code here
    if not root:
        return []
    queue = [root]
    outList = []
    while queue:
        res = []
        i = 0
        numberFlag = len(queue)  # 这一步记录当前层中节点的个数
        while i < numberFlag:  # 这里再遍历每一层
            point = queue.pop(0)
            res.append(point.val)
            if point.left:
                queue.append(point.left)
            if point.right:
                queue.append(point.right)
            i += 1
        outList.append(res)
    print(outList)
